package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.order.OrderFormDTO;
import com.rc.pojo.dto.order.OrderQuery;
import com.rc.pojo.po.Order;
import com.rc.pojo.vo.order.OrderPayListVO;
import com.rc.pojo.vo.order.OrderVO;
import com.rc.pojo.vo.order.PageOrderVO;
import com.rc.web.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 *  控制层。
 *
 * @author sym
 * @since 2024-06-05
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单")
@RequiredArgsConstructor
@Validated
public class OrderController {
    private final OrderService orderService;

    @PostMapping
    @ApiOperation("创建订单")
    @WithoutTenant
    public Order createOrder(@Validated @RequestBody OrderFormDTO dto){
       return orderService.createOrder(dto);
    }

    @PutMapping("/verify")
    @ApiOperation("订单核销")
    @WithoutTenant
    public void verifyOrder(@RequestParam @NotNull Long orderId) {
        orderService.verifyOrder(orderId);
    }

    @GetMapping("/{id}")
    @ApiOperation("查看订单详情")
    @WithoutTenant
    public OrderVO getOneById(@PathVariable Long id){
        return orderService.getOneById(id);
    }

    @GetMapping("/list")
    @ApiOperation("用户查看订单列表")
    @WithoutTenant
    public List<OrderVO> getList(){
        return orderService.getConOrderList();
    }

    @PostMapping("pay")
    @ApiOperation("用户支付订单")
    @WithoutTenant
    public void payOrder(Long orderId,Long addressId){
        orderService.payOrder(orderId,addressId);
    }

    @GetMapping("/page")
    @ApiOperation("分页查看order")
    public Page<PageOrderVO> getPage(OrderQuery query){
        return orderService.getPage(query);
    }

    @GetMapping("/payList")
    @ApiOperation("支付信息")
    @WithoutTenant
    public List<OrderPayListVO> getPayList(){
        return orderService.getPayList();
    }

    @DeleteMapping("/cancelOder")
    @ApiOperation("取消订单")
    @WithoutTenant
    public void canOder(@NotNull Long orderId){
        orderService.cancelOder(orderId);
    }
}
